package ch.uzh.ifi.seal.ssqa.importer.versioncontrol;

import java.util.Map;

import net.sourceforge.clearcase.ClearCaseCLIImpl;
import net.sourceforge.clearcase.commandline.CleartoolCommandLine;

import org.eclipse.jface.preference.IPreferenceStore;

import ch.uzh.ifi.seal.ssqa.SsqaPlugin;
import ch.uzh.ifi.seal.ssqa.preferences.PreferenceConstants;

public class ClearCaseVOBMounter {
	
	ClearCaseCLIImpl cc; 
	
	public void mountVob(String vob){
		/* FIXME check whether mount setting in the preference is alreaday mounted */
		CleartoolCommandLine ct = new CleartoolCommandLine("mount");
		ct.addElement("\\"+vob);
		Map<String,String[]> cmdResult = new ClearCaseCommand(ct).execute();
		System.out.println("[Cleartool Command \"mount\" Success]: " + cmdResult.get(ClearCaseCommand.SUCCEED));
		System.out.println("[Cleartool Command \"mount\" Fail]: " + cmdResult.get(ClearCaseCommand.FAIL));
	}
	
	public void mountConfiguredVobs(){
		IPreferenceStore store = SsqaPlugin.getDefault().getPreferenceStore();
		String[] vobs = store.getString(PreferenceConstants.CC_VOBS).split(",");
		for(String vob : vobs){
			this.mountVob(vob.trim());
		}
	}
	
	public void unmountVob(String vob){
		cc.unmountVob(vob);
	}
	
	public void unmountAllVobs(){
		CleartoolCommandLine ct = new CleartoolCommandLine("umount");
		ct.addOption("-all");
		Map<String,String[]> cmdResult = new ClearCaseCommand(ct).execute();
		System.out.println("[Cleartool Command \"umount\" Success]: " + cmdResult.get(ClearCaseCommand.SUCCEED));
		System.out.println("[Cleartool Command \"umount\" Fail]: " + cmdResult.get(ClearCaseCommand.FAIL));
	}
}
